package cn.itcast.controller;

import cn.itcast.pojo.Clazz;
import cn.itcast.pojo.Result;
import cn.itcast.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    //.依赖注入
    @Autowired
    private ClazzService clazzService;

    //3.3.添加班级 接口
    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz) {
        return clazzService.addClazz(clazz);
    }

    //3.1班级列表查询
    @GetMapping
    public Result findAll(
            String name,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) {
        return clazzService.findAll(name, begin, end, page, pageSize);
    }

    //3.2.根据id删除班级
    @DeleteMapping("/{id}")

    public Result deleteById(@PathVariable Integer id) {
        return clazzService.deleteById(id);
    }

    //3.4.根据id查询班级
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        return clazzService.selectById(id);
    }

    //3.5.修改班级
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        return clazzService.update(clazz);
    }


    //3.6.查询所有班级人员信息
    @GetMapping("/list")
    public Result searchAll() {
        return clazzService.searchAll();
    }


}
